<?php
$_ENV["SITE_ROOT"]=$_SERVER["DOCUMENT_ROOT"].'/web/';  
include_once $_ENV["SITE_ROOT"]."/config_local.php";
include_once $_ENV["SITE_ROOT"]."/config.php"; 
include_once $_ENV["SITE_ROOT"]."/lib/my/funcs_charset.php"; 

$id = (int)$_GET['id'];
$p = (int) $_GET['p'];
$iid = (int)$_GET['iid'];

if ($iid) {
$res = execsql("SELECT `clicks`, `pmin`, `max`, `min`, `id` FROM `klienti_web_direct` WHERE `id_iter` = $iid");
while ($a = mysql_fetch_row($res)) {
$c = round($a[0] * $p / 100);
$out[] = array("id" => $a[4], 
			 "clicks" => $c,
			 "pmin" => $a[1] * 30,
			 "max" => $a[2] * 30,
			 "min" => $a[3] * 30
			 );		
}
} else {
$a = mysql_fetch_row(execsql("SELECT `clicks`, `pmin`, `max`, `min` FROM `klienti_web_direct` WHERE `id` = $id"));
$c = round($a[0] * $p / 100);
/*$out[] = array("id" => $id, 
			 "clicks" => $c,
			 "pmin" => $a[1] * 30 * $c,
			 "max" => $a[2] * 30 * $c,
			 "min" => $a[3] * 30 * $c
			 );*/
$out[] = array("id" => $id, 
			 "clicks" => $c,
			 "pmin" => $a[1] * 30,
			 "max" => $a[2] * 30,
			 "min" => $a[3] * 30
			 );			 
}

print(json_encode($out));
/*$fp = fopen("dd", "w");
fputs($fp, json_encode($out));
fclose($fp);*/
?>
